<html>
    <head>
        {php}html_header_show();{/php}

        <link rel="stylesheet" href="{$FORM_ACTION}/patients/css/datepicker.css" type="text/css"/>
        <link rel="stylesheet" href="{$FORM_ACTION}/library/js/redmond/jquery-ui-1.10.3.custom.min.css" type="text/css"/>
        <script type="text/javascript" src="{$FORM_ACTION}/library/js/jquery-1.10.0.min.js"></script>
        <script type="text/javascript" src="{$FORM_ACTION}/library/js/jquery-ui-1.10.3.custom.min2.js"></script>
        <script type="text/javascript" src="{$FORM_ACTION}/library/dialog.js"></script>
        <script type="text/javascript" src="{$FORM_ACTION}/library/textformat.js"></script>
        <script type="text/javascript" src="{$FORM_ACTION}/patients/js/jquery.ui.datepicker.js"></script>
        <script type="text/javascript" src="{$FORM_ACTION}/patients/js/jquery.mask.min.js"></script>
        <script type="text/javascript">
            var mypcc = '{php} echo $GLOBALS['phone_country_code'] {/php}';
            {
                literal
            }
            // Only load jquery if not already closing. This page serves two purposes now,
            //  for entring of vitals and for graphing/trending previous vitals by being embedded
            //  in the interface/patient_file/encounter/trend_form.php page.
            if (typeof jQuery == 'undefined') {
                document.write("<script type='text/javascript' src='{/literal}{php}echo $GLOBALS['webroot'];{/php}{literal}/library/js/jquery.js'><\/script>")
            }
        </script>
        <script language="javascript">
            // This variable is used to instantiate the SDK.
            var VITALS_OBJECTID_STRING = "WelchAllyn.Vitals2";
            var VITALS_TIMEOUT = 2000; //increase for Citrix thin-client
            var GLOBALSDK = null; // This is the object reference to the ActiveX object.
            // it is here to persist the SDK object throughout
            // the course of the application lifetime.

            var DEVICECONNECTED = false;
            
            getSDKObject();
            GLOBALSDK.AutoDisplay = true; //WYSIWYG to device display
            GLOBALSDK.MonitoringMode = true; //Retrieve values while device is still processing data.

            function getSDKObject()
            {
                try
                {
                    GLOBALSDK = new ActiveXObject(VITALS_OBJECTID_STRING);

                    if (GLOBALSDK == null)
                    {
                        alert("Vitals SDK was not instantiated");
                    }

                }
                catch (createerror)
                {
                    alert("Exception caught while instantiating Vitals object !" + createerror.number + ": " + createerror.description);
                }
                return(GLOBALSDK);
            }

            //Function does everything in one shot!
            // You may want a different approach where Scan, Connect, and Clear are called separately from
            //  retrieving readings.
            function btnConnect_onclick() {
                var Device;
                var Reading;
                var x;

                GLOBALSDK.Timeout = VITALS_TIMEOUT;
                //AutoScan (waits up to timeout when synch is true)
                // You may provide your own config file and bypass the autoscan
                GLOBALSDK.ScanDevices(true);
                try
                {
                    //Retrieve first connected device
                    // if true, will block up to timeout
                    Device = GLOBALSDK.Connect(true); //will throw exception if device not found (when blocking mode is true)
                    //document.vitals.mytext.value = "Device connected on: " + Device.ConnectionKey; //treat as opaque identifier
                    //Get display reading
                    Reading = Device.GetCurrentReading();
                    
                    $("#bps_input").val(Reading.Systolic);
                    $("#bpd_input").val(Reading.Diastolic);
                    $("#oxygen_saturation_input").val(Reading.O2Sat);
                    $("#pulse_input").val(Reading.Pulse);
                    $("#height_input_metric").val(Reading.Height);
                    $("#height_input_metric").click();           
                    $("#weight_input_metric").val(Reading.Weight);
                    $("#weight_input_metric").click();
                    $("#respiration_input").val(Reading.Respiration);
                    $("#temperature_input_metric").val(Reading.BMI);
                                      
                    /*var string = "sys.value = "+Reading.Systolic+"\n";
                    string+= "dias.value =" + Reading.Diastolic+"\n";
                    string+= "HR.value =" + Reading.HR+"\n";
                    string+= "spo2.value =" + Reading.O2Sat+"\n";
                    string+= "pulse.value =" + Reading.Pulse+"\n";
                    string+= "height.value =" + Reading.Height+"\n";
                    string+= "weight.value =" + Reading.Weight+"\n";
                    string+= "pain.value =" + Reading.Pain+"\n";
                    string+= "resp.value =" + Reading.Respiration+"\n";
                    string+= "temp.value =" + Reading.BMI+"\n";
                    alert(string);
                    */
                   
                    //uncomment code to see device clear
                    /*		try {
                     Device.ResetDevice(); //unsupported on Spot LXi
                     }
                     catch (Error) {;} //ignore error
                     Device.EraseCycleData();*/
                }
                catch (Error)
                {
                    
                    alert("Unable to connect to a device! = "+Error);
                    $("#bps_input").val('');
                    $("#bpd_input").val('');
                    $("#oxygen_saturation_input").val('');
                    $("#pulse_input").val('');
                    $("#height_input_metric").val('');
                    $("#height_input_metric").click();           
                    $("#weight_input_metric").val('');
                    $("#weight_input_metric").click();
                    $("#respiration_input").val('');
                    $("#temperature_input_metric").val('');
                }
                finally
                {
                    GLOBALSDK.Disconnect();
                }
            }
            
            $(document).ready(function() {
                $("#equipo").click(function(e) {
                    e.preventDefault();           
                    btnConnect_onclick();
                });
            });

        </script>

        <style type="text/css" title="mystyles" media="all">
            body {
                color: #444444;
                font-family: 'trebuchet MS','Lucida sans',Arial;
                font-size: 14px;
                margin: auto;
                padding: 5px 5px 0;
            }

            table {
                border-collapse: collapse; /* IE7 and lower */
                border-spacing: 0;
                width: 100%;    
            }

            /*----------------------*/

            .zebra {
                background-color: #FFFFFF;
                font-size: 11px;
                width: 90%;
            }

            .zebra td, .zebra th {
                padding: 0 13px;
                border-bottom: 1px solid #f2f2f2;    
            }

            .zebra tbody tr:nth-child(even) {
                background: #f5f5f5;
                -webkit-box-shadow: 0 1px 0 rgba(255,255,255,.8) inset; 
                -moz-box-shadow:0 1px 0 rgba(255,255,255,.8) inset;  
                box-shadow: 0 1px 0 rgba(255,255,255,.8) inset;        
            }

            .zebra th {
                text-align: left;
                text-shadow: 0 1px 0 rgba(255,255,255,.5); 
                border-bottom: 1px solid #ccc;
                background-color: #eee;
                background-image: -webkit-gradient(linear, left top, left bottom, from(#f5f5f5), to(#eee));
                background-image: -webkit-linear-gradient(top, #f5f5f5, #eee);
                background-image:    -moz-linear-gradient(top, #f5f5f5, #eee);
                background-image:     -ms-linear-gradient(top, #f5f5f5, #eee);
                background-image:      -o-linear-gradient(top, #f5f5f5, #eee); 
                background-image:         linear-gradient(top, #f5f5f5, #eee);
                font-size: 15px;
            }

            .zebra th:first-child {
                -moz-border-radius: 6px 0 0 0;
                -webkit-border-radius: 6px 0 0 0;
                border-radius: 6px 0 0 0;  
            }

            .zebra th:last-child {
                -moz-border-radius: 0 6px 0 0;
                -webkit-border-radius: 0 6px 0 0;
                border-radius: 0 6px 0 0;
            }

            .zebra th:only-child{
                -moz-border-radius: 6px 6px 0 0;
                -webkit-border-radius: 6px 6px 0 0;
                border-radius: 6px 6px 0 0;
            }

            .zebra tfoot td {
                border-bottom: 0;
                border-top: 1px solid #fff;
                background-color: #f1f1f1;  
            }

            .zebra tfoot td:first-child {
                -moz-border-radius: 0 0 0 6px;
                -webkit-border-radius: 0 0 0 6px;
                border-radius: 0 0 0 6px;
            }

            .zebra tfoot td:last-child {
                -moz-border-radius: 0 0 6px 0;
                -webkit-border-radius: 0 0 6px 0;
                border-radius: 0 0 6px 0;
            }

            .zebra tfoot td:only-child{
                -moz-border-radius: 0 0 6px 6px;
                -webkit-border-radius: 0 0 6px 6px;
                    border-radius: 0 0 6px 6px;
            }
        </style>
        {/literal}
    </head>



    <body>

        <form name="vitals" method="post" action="{$FORM_ACTION}/interface/forms/vitals/save_pat.php{$medicoIni}" onSubmit="">

            <div class="borde_normal">
                <span class="historial_paciente"><i class="icon-bar-chart" style="font-size: 1.4em;"></i> Signos Vitales</span>

                <a href="" id="ok" onclick="document.forms[0].submit();
                return false;"  class="css_button"><span><i class="icon-ok-sign" style="font-size: 25px;"></i> {xl t="Save Form"}</span></a>
            <a href="" id="equipo" class="css_button" title="Obtener datos desde el equipo de Signos Vitales"><span><i class="icon-dashboard" style="font-size: 25px;"></i> Obtener datos</span></a>
                <!--a href="" id="cancel" class="css_button"><span><i class="icon-remove-sign" style="font-size: 25px;"></i> {xl t="Cancel"}</span></a-->
            </div>


            <h2 style="font-size: 15px;
                margin-bottom: 5px;
                margin-top: 5px;">Fecha: <input type='text' size='14' name='date' id='date'
                            value='{$vitals->get_date()|date_format:"%d-%m-%Y"}' />
                <!--<img src='{$FORM_ACTION}/interface/pic/show_calendar.gif' id='img_date' align='absbottom'
                     width='24' height='22' border='0' alt='[?]' style='cursor:pointer' />--></h2>


            <div id="display">
                <table style="border-spacing: 0px; font-size: 11px; margin: 0px auto;">
                    <tr>
                        <td>
                            <table class="zebra">
                                <tr>
                                    <th colspan="3" align="center" style="text-align:center;" class='patient_info_left'><span>Signos vitales</span></th>

                                </tr>
                                <tr>
                                    <th align="left">{xl t="Name"}</th><th align="left">{xl t="Unit"}</th><th>Valor</th>
                                </tr>

                                {if $units_of_measurement == 4}<tr class="hide">{else}<tr>{/if}
                                    {if $units_of_measurement == 2}<td class="unfocus graph" id="weight">{else}<td class="graph" id="weight">{/if}{xl t="Weight"}</td>
                                    {if $units_of_measurement == 2}<td class="unfocus">{else}<td>{/if}{xl t="lbs"}</td>
                                    {if $units_of_measurement == 2}<td class="valuesunfocus">{else}<td class='currentvalues'>{/if}
                                        <input type="text" size='5' name='weight' id='weight_input' value="{if $vitals->get_weight() != 0}{$vitals->get_weight()}{/if}" onClick="convLbtoKg('weight_input');"/>
                                    </td>		
                                </tr>

                                {if $units_of_measurement == 3}<tr class="hide">{else}<tr>{/if}
                                    {if $units_of_measurement == 1}<td class="unfocus graph" id="weight_metric">{else}<td class="graph" id="weight_metric">{/if}{xl t="Weight"}</td>
                                    {if $units_of_measurement == 1}<td class="unfocus">{else}<td>{/if}{xl t="kg"}</td>
                                    {if $units_of_measurement == 1}<td class="valuesunfocus">{else}<td class='currentvalues'>{/if}
                                        <input type="text" size='5' name='weight_input_metric' id='weight_input_metric' value="{if $vitals->get_weight() != 0}{math equation="number * constant" number=$vitals->get_weight() constant=0.45359237 format="%.2f"}{/if}" onClick="convKgtoLb('weight_input');"/>
                                    </td>
                                </tr>

                                {if $units_of_measurement == 4}<tr class="hide">{else}<tr>{/if}
                                    {if $units_of_measurement == 2}<td class="unfocus graph" id="height">{else}<td class="graph" id="height">{/if}{xl t="Height"}</td>
                                    {if $units_of_measurement == 2}<td class="unfocus">{else}<td>{/if}{xl t="in"}</td>
                                    {if $units_of_measurement == 2}<td class="valuesunfocus">{else}<td class='currentvalues'>{/if}
                                        <input type="text" size='5' name='height' id='height_input' value="{if $vitals->get_height() != 0}{$vitals->get_height()}{/if}" onClick="convIntoCm('height_input');"/>
                                    </td>
                                </tr>

                                {if $units_of_measurement == 3}<tr class="hide">{else}<tr>{/if}
                                    {if $units_of_measurement == 1}<td class="unfocus graph" id="height_metric">{else}<td class="graph" id="height_metric">{/if}{xl t="Height"}</td>
                                    {if $units_of_measurement == 1}<td class="unfocus">{else}<td>{/if}{xl t="cm"}</td>
                                    {if $units_of_measurement == 1}<td class="valuesunfocus">{else}<td class='currentvalues'>{/if}
                                        <input type="text" size='5' name='height_input_metric' id='height_input_metric' value="{if $vitals->get_height() != 0}{math equation="number * constant" number=$vitals->get_height() constant=2.54 format="%.2f"}{/if}" onClick="convCmtoIn('height_input');"/>
                                    </td>
                                </tr>

                                <tr><td class="graph" id="bps">{xl t="BP Systolic"}</td><td>{xl t="mmHg"}</td>
                                    <td class='currentvalues'><input type="text" size='5'
                                                                     name='bps' id='bps_input' value="{$vitals->get_bps()}"/></td>
                                </tr>
                                <tr><td class="graph" id="bpd">{xl t="BP Diastolic"}</td><td>{xl t="mmHg"}</td>
                                    <td class='currentvalues'><input type="text" size='5'
                                                                     name='bpd' id='bpd_input' value="{$vitals->get_bpd()}"/></td>
                                </tr>
                                <tr><td class="graph" id="pulse">{xl t="Pulse"}</td><td>{xl t="per min"}</td>
                                    <td class='currentvalues'><input type="text" size='5'
                                                                     name='pulse' id='pulse_input' value="{if $vitals->get_pulse() != 0}{$vitals->get_pulse()|string_format:"%.0f"}{/if}"/></td>
                                </tr>
                                <tr><td class="graph" id="respiration">{xl t="Respiration"}</td><td>{xl t="per min"}</td>
                                    <td class='currentvalues'><input type="text" size='5'
                                                                     name='respiration' id='respiration_input' value="{if $vitals->get_respiration() != 0}{$vitals->get_respiration()|string_format:"%.0f"}{/if}"/></td>
                                </tr>

                                {if $units_of_measurement == 4}<tr class="hide">{else}<tr>{/if}
                                    {if $units_of_measurement == 2}<td class="unfocus graph" id="temperature">{else}<td class="graph" id="temperature">{/if}{xl t="Temperature"}</td>
                                    {if $units_of_measurement == 2}<td class="unfocus">{else}<td>{/if}{xl t="F"}</td>
                                    {if $units_of_measurement == 2}<td class="valuesunfocus">{else}<td class='currentvalues'>{/if}
                                        <input type="text" size='5' name='temperature' id='temperature_input' value="{if $vitals->get_temperature() != 0}{$vitals->get_temperature()}{/if}" onChange="convFtoC('temperature_input');"/>
                                    </td>
                                </tr>

                                {if $units_of_measurement == 3}<tr class="hide">{else}<tr>{/if}
                                    {if $units_of_measurement == 1}<td class="unfocus graph" id="temperature_metric">{else}<td class="graph" id="temperature_metric">{/if}{xl t="Temperature"}</td>
                                    {if $units_of_measurement == 1}<td class="unfocus">{else}<td>{/if}{xl t="C"}</td>
                                    {if $units_of_measurement == 1}<td class="valuesunfocus">{else}<td class='currentvalues'>{/if}
                                        <input type="text" size='5' id='temperature_input_metric' value="{if $vitals->get_temperature() != 0}{math equation="(number - constant2 ) * constant" number=$vitals->get_temperature() constant=0.5556 constant2=32 format="%.2f"}{/if}" onChange="convCtoF('temperature_input');"/>
                                    </td>
                                </tr>

                                <tr><td>{xl t="Temp Location"}<td>&nbsp;</td></td>
                                    <td class='currentvalues'><select name="temp_method" id='temp_method'/><option value=""> </option>  
                                <option value="Oral"              {if $vitals->get_temp_method() == "Oral"              || $vitals->get_temp_method() == 2 } selected{/if}>{xl t="Oral"}
                                <option value="Tympanic Membrane" {if $vitals->get_temp_method() == "Tympanic Membrane" || $vitals->get_temp_method() == 1 } selected{/if}>{xl t="Tympanic Membrane"}
                                <option value="Rectal"            {if $vitals->get_temp_method() == "Rectal"            || $vitals->get_temp_method() == 3 } selected{/if}>{xl t="Rectal"}
                                <option value="Axillary"          {if $vitals->get_temp_method() == "Axillary"          || $vitals->get_temp_method() == 4 } selected{/if}>{xl t="Axillary"}
                                <option value="Temporal Artery"   {if $vitals->get_temp_method() == "Temporal Artery" } selected{/if}>{xl t="Temporal Artery"}
                                    </select></td>
                                    </tr>

                                <tr><td class="graph" id="oxygen_saturation">{xl t="Oxygen Saturation"}</td><td>{xl t="%"}</td>
                                    <td class='currentvalues'><input type="text" size='5'
                                                                     name='oxygen_saturation' id='oxygen_saturation_input' value="{if $vitals->get_oxygen_saturation() != 0}{$vitals->get_oxygen_saturation()|string_format:"%.0f"}{/if}"/></td>
                                </tr>

                                {if $units_of_measurement == 4}<tr class="hide">{else}<tr>{/if}
                                    {if $units_of_measurement == 2}<td class="unfocus graph" id="head_circ">{else}<td class="graph" id="head_circ">{/if}{xl t="Head Circumference"}</td>
                                    {if $units_of_measurement == 2}<td class="unfocus">{else}<td>{/if}{xl t="in"}</td>
                                    {if $units_of_measurement == 2}<td class="valuesunfocus">{else}<td class='currentvalues'>{/if}
                                        <input type="text" size='5' name='head_circ' id='head_circ_input' value="{if $vitals->get_head_circ() != 0}{$vitals->get_head_circ()}{/if}" onChange="convIntoCm('head_circ_input');"/>
                                    </td>
                                </tr>

                                {if $units_of_measurement == 3}<tr class="hide">{else}<tr>{/if}
                                    {if $units_of_measurement == 1}<td class="unfocus graph" id="head_circ_metric">{else}<td class="graph" id="head_circ_metric">{/if}{xl t="Head Circumference"}</td>
                                    {if $units_of_measurement == 1}<td class="unfocus">{else}<td>{/if}{xl t="cm"}</td>
                                    {if $units_of_measurement == 1}<td class="valuesunfocus">{else}<td class='currentvalues'>{/if}
                                        <input type="text" size='5' id='head_circ_input_metric' value="{if $vitals->get_head_circ() != 0}{math equation="number * constant" number=$vitals->get_head_circ() constant=2.54 format="%.2f"}{/if}" onChange="convCmtoIn('head_circ_input');"/>
                                    </td>
                                </tr>

                                {if $units_of_measurement == 4}<tr class="hide">{else}<tr>{/if}
                                    {if $units_of_measurement == 2}<td class="unfocus graph" id="waist_circ">{else}<td class="graph" id="waist_circ">{/if}{xl t="Waist Circumference"}</td>
                                    {if $units_of_measurement == 2}<td class="unfocus">{else}<td>{/if}{xl t="in"}</td>
                                    {if $units_of_measurement == 2}<td class="valuesunfocus">{else}<td class='currentvalues'>{/if}
                                        <input type="text" size='5' name='waist_circ' id='waist_circ_input' value="{if $vitals->get_waist_circ() != 0}{$vitals->get_waist_circ()}{/if}" onChange="convIntoCm('waist_circ_input');"/>
                                    </td>
                                </tr>

                                {if $units_of_measurement == 3}<tr class="hide">{else}<tr>{/if}
                                    {if $units_of_measurement == 1}<td class="unfocus graph" id="waist_circ_metric">{else}<td class="graph" id="waist_circ_metric">{/if}{xl t="Waist Circumference"}</td>
                                    {if $units_of_measurement == 1}<td class="unfocus">{else}<td>{/if}{xl t="cm"}</td>
                                    {if $units_of_measurement == 1}<td class="valuesunfocus">{else}<td class='currentvalues'>{/if}
                                        <input type="text" size='5' id='waist_circ_input_metric' value="{if $vitals->get_waist_circ() != 0}{math equation="number * constant" number=$vitals->get_waist_circ() constant=2.54 format="%.2f"}{/if}" onChange="convCmtoIn('waist_circ_input');"/>
                                    </td>
                                </tr>

                                <tr><td class="graph" id="BMI">{xl t="BMI"}</td><td>{xl t="kg/m^2"}</td>
                                    <td class='currentvalues'><input type="text" size='5' readonly="readonly"
                                                                     name='BMI' id='BMI_input' value="{if $vitals->get_BMI() != 0}{$vitals->get_BMI()|substr:0:5}{/if}"/></td>
                                </tr>

                                <tr><td>{xl t="BMI Status"}</td><td>{xl t="Type"}</td>
                                    <td class='currentvalues'><input type="text" size='15' readonly="readonly"
                                                                     name="BMI_status" id="BMI_status' value="{$vitals->get_BMI_status()}"/></td>

                                </tr>
                            </table>
                        </td>
                        <td>
                            <table class="zebra" style="margin-top: -68px;">
                                <tr>
                                    <th colspan="3" align="left" style="text-align:center;" class='patient_info_left'><span>Composici&oacute;n corporal</span></th>
                                </tr>
                                <tr>
                                    <th align="left">{xl t="Name"}</th><th align="left">{xl t="Unit"}</th><th>Valor</th>
                                </tr>
                                <tr>
                                    <td>Porcentaje de grasa corporal</td>
                                    <td>%</td>
                                    <td class='currentvalues'><input type="text" size='5' name="bodyfatpercent" id='bodyfatpercent' value="" /></td>
                                </tr>

                                <tr>
                                    <td>Nivel de grasa corporal</td>
                                    <td>&nbsp;</td>
                                    <td class='currentvalues'><input type="text" size='5' name="bodyfatrange" id='bodyfatrange' value="" /></td>
                                </tr>

                                <tr>
                                    <td>Porcentaje de agua en el cuerpo</td>
                                    <td>%</td>
                                    <td class='currentvalues'><input type="text" size='5' name="bodywaterpercent" id='bodywaterpercent' value="" /></td>
                                </tr>

                                <tr>
                                    <td>Masa de agua en el cuerpo</td>
                                    <td>&nbsp;</td>
                                    <td class='currentvalues'><input type="text" size='5' name="bodywatermass" id='bodywatermass' value="" /></td>
                                </tr>

                                <tr>
                                    <td>Nivel de grasa viceral</td>
                                    <td>&nbsp;</td>
                                    <td class='currentvalues'><input type="text" size='5' name="visceralfatrating" id='visceralfatrating' value="" /></td>
                                </tr>

                                <tr>
                                    <td>Consumo cal&oacute;rico diario</td>
                                    <td>&nbsp;</td>
                                    <td class='currentvalues'><input type="text" size='5' name="dailycalorieintake" id='dailycalorieintake' value="" /></td>
                                </tr>

                                <tr>
                                    <td>Edad metab&oacute;lica</td>
                                    <td>&nbsp;</td>
                                    <td class='currentvalues'><input type="text" size='5' name="metabolicage" id='metabolicage' value="" /></td>
                                </tr>

                                <tr>
                                    <td>Masa muscular</td>
                                    <td>&nbsp;</td>
                                    <td class='currentvalues'><input type="text" size='5' name="musclemass" id='musclemass' value="" /></td>
                                </tr>

                                <tr>
                                    <td>Condici&oacute;n f&iacute;sica</td>
                                    <td>&nbsp;</td>
                                    <td class='currentvalues'><input type="text" size='5' name="physiquerating" id=physiquerating' value="" /></td>
                                </tr>

                                <tr>
                                    <td>Masa &oacute;sea</td>
                                    <td>&nbsp;</td>
                                    <td class='currentvalues'><input type="text" size='5' name="bonemass" id='bonemass' value="" /></td>
                                </tr>

                                <tr>
                                    <td>Masa grasa</td>
                                    <td>&nbsp;</td>
                                    <td class='currentvalues'><input type="text" size='5' name="fatmass" id='fatmass' value="" /></td>
                                </tr>

                                <tr>
                                    <td>Masa libre de grasa</td>
                                    <td>&nbsp;</td>
                                    <td class='currentvalues'><input type="text" size='5' name="fatfreemass" id='fatfreemass' value="" /></td>
                                </tr>

                                <tr>
                                    <td>Tasa metabolica basal</td>
                                    <td>&nbsp;</td>
                                    <td class='currentvalues'><input type="text" size='5' name="basalmetabolicrate" id='basalmetabolicrate' value="" /></td>
                                </tr>

                                <tr><td>{xl t="Other Notes"}<td>&nbsp;</td></td>
                                    <td class='currentvalues'><input type="text" size='20'
                                                                     name="note" id='note' value="{$vitals->get_note()}" /></td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
            </div>
            <input type="hidden" name="id" id='id' value="{$vitals->get_id()}" />
            <input type="hidden" name="activity" id='activity' value="{$vitals->get_activity()}">
            <input type="hidden" name="pid" id='pid' value="{$vitals->get_pid()}">
            <input type="hidden" name="process" id='process' value="true">
        </form>
    </body>

    <script language="javascript">
            var formdate = '{$vitals->get_date()|date_format:"%Y%m%d"}';
            // vitals array elements are in the format:
            //   date-height-weight-head_circumference
            var vitals = new Array();
            // get values from the current form elements
            vitals[0] = formdate + '-{$vitals->get_height()}-{$vitals->get_weight()}-{$vitals->get_head_circ()}';
            // historic values
            {foreach item = result from = $results}
            vitals[vitals.length] = '{$result.date|date_format:"%Y%m%d"}-{$result.height}-{$result.weight}-{$result.head_circ}';
            {/foreach}
                    var webroot = '{$FORM_ACTION}';
            var pid = '{$vitals->get_pid()}';
            var cancellink = '{$DONT_SAVE_LINK}';
            {
                literal
            }

            $(document).ready(function() {

                $("#cancel").click(function() {
                    parent.jQuery.fancybox.close();
                });

            });

            function convLbtoKg(name) {
                var lb = $("#" + name).val();
                if (lb == "0") {
                    $("#" + name + "_metric").val("0");
                }
                else if (lb == parseFloat(lb)) {
                    kg = lb * 0.45359237;
                    kg = kg.toFixed(2);
                    $("#" + name + "_metric").val(kg);
                }
                else {
                    $("#" + name + "_metric").val("");
                }

                if (name == "weight") {
                    calculateBMI();
                }
            }

            function convKgtoLb(name) {
                var kg = $("#" + name + "_metric").val();
                if (kg == "0") {
                    $("#" + name).val("0");
                }
                else if (kg == parseFloat(kg)) {
                    lb = kg / 0.45359237;
                    lb = lb.toFixed(2);
                    $("#" + name).val(lb);
                }
                else {
                    $("#" + name).val("");
                }

                if (name == "weight_input") {
                    calculateBMI();
                }
            }

            function convIntoCm(name) {
                var inch = $("#" + name).val();
                if (inch == "0") {
                    $("#" + name + "_metric").val("0");
                }
                else if (inch == parseFloat(inch)) {
                    cm = inch * 2.54;
                    cm = cm.toFixed(2);
                    $("#" + name + "_metric").val(cm);
                }
                else {
                    $("#" + name + "_metric").val("");
                }

                if (name == "height_input") {
                    calculateBMI();
                }
            }

            function convCmtoIn(name) {
                var cm = $("#" + name + "_metric").val();
                if (cm == "0") {
                    $("#" + name).val("0");
                }
                else if (cm == parseFloat(cm)) {
                    inch = cm / 2.54;
                    inch = inch.toFixed(2);
                    $("#" + name).val(inch);
                }
                else {
                    $("#" + name).val("");
                }

                if (name == "height_input") {
                    calculateBMI();
                }
            }

            function convFtoC(name) {
                var Fdeg = $("#" + name).val();
                if (Fdeg == "0") {
                    $("#" + name + "_metric").val("0");
                }
                else if (Fdeg == parseFloat(Fdeg)) {
                    Cdeg = (Fdeg - 32) * 0.5556;
                    Cdeg = Cdeg.toFixed(2);
                    $("#" + name + "_metric").val(Cdeg);
                }
                else {
                    $("#" + name + "_metric").val("");
                }
            }

            function convCtoF(name) {
                var Cdeg = $("#" + name + "_metric").val();
                if (Cdeg == "0") {
                    $("#" + name).val("0");
                }
                else if (Cdeg == parseFloat(Cdeg)) {
                    Fdeg = (Cdeg / 0.5556) + 32;
                    Fdeg = Fdeg.toFixed(2);
                    $("#" + name).val(Fdeg);
                }
                else {
                    $("#" + name).val("");
                }
            }

            function calculateBMI() {
                var bmi = 0;
                var height = $("#height_input").val();
                var weight = $("#weight_input").val();
                if (height == 0 || weight == 0) {
                    $("#BMI").val("");
                }
                else if ((height == parseFloat(height)) && (weight == parseFloat(weight))) {
                    bmi = weight / height / height * 703;
                    bmi = bmi.toFixed(1);
                    $("#BMI_input").val(bmi);
                }
                else {
                    $("#BMI_input").val("");
                }
            }

            $("#date").datepicker({
                showOn: "button",
                buttonImage: webroot + "/patients/images/calendar-green.gif",
                dateFormat: 'dd-mm-yy',
                changeMonth: true,
                changeYear: true,
                buttonImageOnly: true
            });

            $(".ui-datepicker-trigger").after(" <span>(dd-mm-aaaa)</span> ");

            $("#date").mask("99-99-9999");

    </script>
    {/literal}

</html>
